package com.zjsru.oneDay202204;

/**
 * @Author: likew
 * @Date: 2022/4/9
 *
 * 到达终点
 * 从点 (x, y) 可以转换到 (x, x+y)  或者 (x+y, y)。
 *
 * 输入: sx = 1, sy = 1, tx = 3, ty = 5
 * 输出: true
 * 解释:
 * 可以通过以下一系列转换从起点转换到终点：
 * (1, 1) -> (1, 2)
 * (1, 2) -> (3, 2)
 * (3, 2) -> (3, 5)
 *
 * 输入: sx = 1, sy = 1, tx = 2, ty = 2
 * 输出: false
 */
public class reachingPoints {
    public boolean reachingPoints(int sx, int sy, int tx, int ty) {
        if(sx > tx || sy > ty){
            return false;
        }
        if(sx == tx && (ty - sy) % sx == 0){
            return true;
        }
        if(sy == ty && (tx - sx) % sy == 0){
            return true;
        }
        
        return reachingPoints(sx, sy, tx % ty, ty % tx);
    }
    
    public static void main(String[] args) {
        reachingPoints reachingPoints = new reachingPoints();
        int sx = 1,sy = 1,tx = 3,ty = 5;
        System.out.println(reachingPoints.reachingPoints(sx, sy, tx, ty));
    }
}
